package com.ebuy.shopping.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ebuy.shopping.common.base.BaseController;
import com.ebuy.shopping.exception.BusinessException;
import com.ebuy.shopping.exception.ParameterException;
import com.ebuy.shopping.service.ITestService;

@Controller
@RequestMapping("/test")
public class TestController extends BaseController
{
    @Resource
    private ITestService testService;

    @RequestMapping(value = "{id}/controller", method = RequestMethod.GET)
    public void controller(@PathVariable
    int id) throws Exception
    {
        switch (id)
        {
        case 1:
            throw new BusinessException("10", "controller10");
        case 2:
            throw new BusinessException("20", "controller20");
        case 3:
            throw new BusinessException("30", "controller30");
        case 4:
            throw new BusinessException("40", "controller40");
        case 5:
            throw new BusinessException("50", "controller50");
        default:
            throw new ParameterException("Controller Parameter Error");
        }
    }

    @RequestMapping(value = "/service", method = RequestMethod.GET)
    public void service(@PathVariable
    int id) throws Exception
    {
        testService.exception(id);
    }

    @RequestMapping(value = "/dao", method = RequestMethod.GET)
    public void dao(@PathVariable
    int id) throws Exception
    {
        System.out.println("-----hhhhhh--");

        testService.dao(id);
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String add() throws Exception
    {
        return "test/demo"; // -->webapp/WEB-INF/pages/user/add.jsp
    }
}
